<%-- 
    Document   : makeTeam
    Created on : Jul 7, 2011, 8:35:52 PM
    Author     : Tyler Powell
--%>

<%@include file="include_header.jsp"%>
<%@include file="verifySession.jsp" %>
<jsp:useBean id="courseData" scope="application" class="edu.gatech.gellinservlet.model.CourseManager" />
<jsp:useBean id="labData" scope="application" class="edu.gatech.gellinservlet.model.LabManager" />
<jsp:useBean id="teamData" scope="application" class="edu.gatech.gellinservlet.model.TeamManager" />

<!DOCTYPE html>
<%
    //Lab aLab = (Lab)session.getAttribute("persistLab");
    //Course aCourse = (Course)session.getAttribute("persistCourse");
    String labName = request.getParameter("labName"); 
    Lab aLab = labData.search(labName); 
    //out.println("labName " + aLab.getName());
    if(aLab != null){
        //Lab aLab = labData.session.getAsearch(labName);
        //get the max team size and team designation from lab and create a new team
        //with the team name

        int maxTeamSize = -1;
        int teamDesignation = -1; 
        maxTeamSize = aLab.getTeamMaxSize();
        teamDesignation = aLab.getTeamDesignation();

        String teamName = request.getParameter("teamName");
        //System.out.println(labData.toString());
        Team aTeam = labData.addTeamToLab(teamName, aLab.getID(), teamData);
        aUser = (User)session.getAttribute("persistUser"); 
        //Team aTeam = teamData.createTeam(teamName, maxTeamSize, teamDesignation);
        //aLab.addTeam(aTeam);
        teamData.add(aTeam);
        //Lab courseLab = labData.searchExtern(aLab.getID(), aCourse.getLabList());
        //courseLab = aLab;
        aTeam.add((Student)aUser);
        ((Student)aUser).addTeam(aTeam);
        teamData.save("teamData.ser");
        labData.save("labData.ser");
        response.sendRedirect("stude_home.jsp?msg=valid");

        out.println("maxTeamSize: " + maxTeamSize + "teamDesignation: " + teamDesignation + "teamName: " + teamName );

    }
%>
        <% } //ends verifySession.jsp, all html is included in else statment %>
